using UnityEngine;
using System.Collections.Generic;

public class GameManager : Singleton<GameManager>
{
	private List<Player> playersToMove;

	private void Awake()
	{
		DontDestroyOnLoad(this);
	}

	public void ChangeFloor(SceneID _ID)
	{
		playersToMove = InitiativeManager.Instance.GetAllPlayers();
		foreach (Player p in playersToMove)
		{
			p.transform.SetParent(null);
			p.gameObject.SetActive(false);
		}

		Application.LoadLevel(_ID.ToString());

		Invoke("RespawnPlayers", 0.5f);
	}

	private void RespawnPlayers()
	{
		Transform[] spawns = FloorSpawns.Instance.floorSpawns;
		for (int i = 0; i < spawns.Length && i < playersToMove.Count; i++)
		{
			playersToMove[i].gameObject.SetActive(true);
			playersToMove[i].transform.position = spawns[i].position;
			Debug.Log(playersToMove[i]);
			playersToMove[i].RecalculateAreas();
		}
		
		Character.CharacterModified();

		GameCamera.Instance.MoveCamera(InitiativeManager.Instance.current);
		GameCamera.Instance.UpdateCharacter();
	}
}
